package com.study.shiro;

import com.study.domain.Account;
import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.SimpleAuthenticationInfo;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.apache.shiro.crypto.hash.Md5Hash;
import org.apache.shiro.subject.PrincipalCollection;

/**
 * 
 * @author chenjie 
 * 密码比较器
 *
 */
public class CustomCredentialsMatcher extends SimpleCredentialsMatcher {

	//密码比较的方法   token代表用户在界面输入的用户名和密码     info代表从数据库中得到加密数据
	public boolean doCredentialsMatch(AuthenticationToken authenticationToken, AuthenticationInfo authenticationInfo) {
		System.out.println("密码验证");
		//1.向下转型
		UsernamePasswordToken upToken = (UsernamePasswordToken) authenticationToken;
		return upToken.getUsername().equals(authenticationInfo.getPrincipals().getPrimaryPrincipal().toString())
				&& String.valueOf(upToken.getPassword()).equals(authenticationInfo.getCredentials().toString());
	}

	
}
